<script setup lang="ts">
import { RouteLocationNormalizedLoaded } from "vue-router";
function getFirstLevelRoute(route: RouteLocationNormalizedLoaded) {
  if (!Array.isArray(route.matched) || route.matched.length === 0) {
    return route;
  }
  return route.matched[0];
}
</script>

<template>
  <div>
    <router-view v-slot="{ Component, route }">
      <keep-alive :max="10">
        <component
          :is="Component"
          :key="getFirstLevelRoute(route).name"
          v-if="getFirstLevelRoute(route).meta.keepAlive"
        />
      </keep-alive>
      <component
        :is="Component"
        :key="getFirstLevelRoute(route).name"
        v-if="!getFirstLevelRoute(route).meta.keepAlive"
      />
    </router-view>
  </div>
</template>

<style scoped>
.logo {
  height: 6em;
  padding: 1.5em;
  will-change: filter;
  transition: filter 300ms;
}
.logo:hover {
  filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vue:hover {
  filter: drop-shadow(0 0 2em #42b883aa);
}
</style>
